package com.company;

import java.io.*;

public class iotest05 {
    public static void main(String[] args)  {
       // FileOutputStream(File file)
       // FileOutputStream(Sting name)
       method();
       //method1();
        method2();
    }
    public static void method()  {
        //默认数据覆盖文件
        FileOutputStream out=null;
        try {
             out= new FileOutputStream("D:\\WeGame\\1.txt");
            out.write(97);
            out.write(98);
            out.write(99);
            out.write(96);

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }


    }
    public static void method1()  {
        //追加数据，不会干掉以前的数据
        FileOutputStream out=null;
        try {
            out= new FileOutputStream("D:\\WeGame\\2.txt",true);
            out.write(97);
            out.write(98);
            out.write(99);
            out.write(96);

        }catch (Exception e){
            e.printStackTrace();
        }finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
    public static void method2()  {
        OutputStream out=null;
        try {
             out= new BufferedOutputStream(new FileOutputStream("D:\\WeGame\\2.txt",true));
            out.write(123);
            out.write(50);
            out.write(48);
            out.write(49);
            //释放资源
            //out.flush();把资源刷出去

        }catch (Exception e){}finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
